#ifndef GLOBAL_H
#define GLOBAL_H
#include "platforms.h"
#define configDir (QDir::homePath() + "/.config/classroom")
#define CONFIG_PATH(name) (configDir + "/" #name)
#define timetableFilePath CONFIG_PATH(timetable.csv)
#define tempTimetableFilePath CONFIG_PATH(temp.csv)
#define studentsFilePath CONFIG_PATH(students.txt)
#define noticeFilePath CONFIG_PATH(notice.txt)
#define subjectsDirPath CONFIG_PATH(text)
#define studentsSessionFilePath CONFIG_PATH(students_session.bin)
#define studentsHistoryFilePath CONFIG_PATH(students_history.txt)
#define MAINFT "黑体"
extern bool liveMode;
extern QScreen* g_primaryScreen;
extern QRect g_screenGeometry, g_availableGeometry;
#define screenx (g_availableGeometry.x())
#define screeny (g_availableGeometry.y())
#define screenw (g_availableGeometry.width())
#define screenh (g_availableGeometry.height())
void initScreenCache();
struct CurrentClassInfo
{
	bool isInClass = false;
	QString subject;
	QTime startTime;
	QTime endTime;
	double progress = 0.0;
};
extern CurrentClassInfo g_currentClassInfo;
class PreventCloseWindow : public QMainWindow
{
	Q_OBJECT
public:
	explicit PreventCloseWindow(QWidget* parent = nullptr) : QMainWindow(parent) {}
protected:
	void closeEvent(QCloseEvent* event) override { event->ignore(); }
};
class Config : public QObject
{
	Q_OBJECT
public:
	static Config& instance();
	bool barrage() const { return m_barrage; }
	void setBarrage(bool value) { m_barrage = value; }
	bool screensaver() const { return m_screensaver; }
	void setScreensaver(bool value) { m_screensaver = value; }
	QString hiddenSubjects() const { return m_hiddenSubjects; }
	void setHiddenSubjects(const QString& value) { m_hiddenSubjects = value; }
	QStringList ganfanTimes() const { return m_ganfanTimes; }
	void setGanfanTimes(const QStringList& value) { m_ganfanTimes = value; }
	QStringList shutdownTimes() const { return m_shutdownTimes; }
	void setShutdownTimes(const QStringList& value) { m_shutdownTimes = value; }
	qint64 enrollmentTimestamp() const { return m_enrollmentTimestamp; }
	void setEnrollmentTimestamp(qint64 value) { m_enrollmentTimestamp = value; }
	qint64 gaokaoTimestamp() const { return m_gaokaoTimestamp; }
	void setGaokaoTimestamp(qint64 value) { m_gaokaoTimestamp = value; }
	void saveConfig();
private:
	explicit Config(QObject* parent = nullptr);
	void loadConfig();
	struct Keys
	{
		static constexpr const char* BARRAGE = "barrage";
		static constexpr const char* SCREENSAVER = "screensaver";
		static constexpr const char* HIDDEN_SUBJECTS = "hidden_subjects";
		static constexpr const char* GANFAN_TIMES = "ganfan_times";
		static constexpr const char* SHUTDOWN_TIMES = "shutdown_times";
		static constexpr const char* ENROLLMENT_TIMESTAMP = "enrollment_timestamp";
		static constexpr const char* GAOKAO_TIMESTAMP = "gaokao_timestamp";
	};
	bool m_barrage = 1, m_screensaver = 1;
	qint64 m_enrollmentTimestamp = QDateTime(QDate(2023, 8, 17), QTime(18, 50)).toSecsSinceEpoch(), m_gaokaoTimestamp = 1780794000;
	QString m_hiddenSubjects;
	QStringList m_ganfanTimes, m_shutdownTimes;
	QSettings* m_settings = nullptr;
};
#endif
